<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import="com.avery.entity.Documentlibrary" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";

List<Documentlibrary> libraries=(ArrayList)request.getAttribute("libraries");
request.setAttribute("locLibraryCount", libraries.size());
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
<head>
<base href="<%=basePath%>">

<meta name="keywords" content="" />
<meta name="description" content="" />
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>Doctaskis</title>
<link href="css/style.css" rel="stylesheet" type="text/css" media="screen" />
<link href="css/jquery-ui.min.css" rel="stylesheet" type="text/css" media="screen" />
<script src="js/jquery-1.7.2.min.js"></script>
<script src="js/jquery-ui-1.10.0.custom.js"></script>
<script type="text/javascript">
var locSelectedDocID;
var locSelectedDocName;

function onLibraryAction(docid,docName){
	locSelectedDocID = docid;
	locSelectedDocName = docName;
	if(docName == "分享库"){
		onOpenLibraryAction();
		return;
	}
	$( "#documentLibraryOp" ).dialog( "open" );
}

function onOpenLibraryAction(){
	//设置路径
  	var shref="documentLibrary.do?actMethod=getDocumentAction&locLibraryID="+locSelectedDocID;
 	window.location.href=shref;
}

function onSaveLibraryAction(){
	if($("#libraryName").val()=="分享库"){
		alert("不可取名为分享库！");
		return;
	}
	//设置路径
  	var shref="documentLibrary.do?actMethod=addDocumentLibraryAction&locLibraryContent="+$("#libraryName").val();
 	window.location.href=shref;
}

function onUpdateLibraryAction(){
	if($("#newLibraryName").val()=="分享库"){
		alert("不可取名为分享库！");
		return;
	}
	//设置路径
  	var shref="documentLibrary.do?actMethod=updateDocumentLibraryAction&locLibraryID="+locSelectedDocID+"&locLibraryContent="+$("#newLibraryName").val();
 	window.location.href=shref;
}

function onDeleteLibraryAction(){
	//设置路径
  	var shref="documentLibrary.do?actMethod=deleteDocumentLibraryAction&locLibraryID="+locSelectedDocID;
 	window.location.href=shref;
}

$(function(){
	$("input:submit,input:reset,button").button();
	$( "#addLibraryDialog" ).dialog({
		autoOpen: false,
		height: 150,
		width: 600,
		modal: true,
		buttons: {
	  			取消:function(){$( this ).dialog( "close" );}
  			}
	 });
	 $( "#updateLibraryDialog" ).dialog({
		autoOpen: false,
		height: 150,
		width: 600,
		modal: true,
		buttons: {
	  			取消:function(){$( this ).dialog( "close" );}
  			}
	 });
	$( "#documentLibraryOp" ).dialog({
		autoOpen: false,
		height: 150,
		width: 600,
		modal: true,
		buttons: {
	  			取消:function(){$( this ).dialog( "close" );}
  			}
	 });
	 $( "#addLibrary" )
		.button()
		.click(function() {
		if($("#libraryCount").val() >= 3){
			alert("暂时本系统的用户库的数量最多只能有五个哦！");
			return;
		}
		$( "#addLibraryDialog" ).dialog( "open" );
	}); 
	 $( "#updateDocLibrary" )
		.button()
		.click(function() {
		$( "#documentLibraryOp" ).dialog("close");
		$( "#updateLibraryDialog" ).dialog( "open" );
		$("#newLibraryName").val(locSelectedDocName);
	});
	
	
});
</script>
</head>
<body>
<input type="hidden" id="libraryCount" value="${locLibraryCount}"></input>
<div id="wrapper">
	<div id="header">
		<div id="logo">
			<h1><a href="#">doctaskis </a></h1>
			<p> BY AVERY HUO</p>
		</div>
		<div id="menu">
			<ul>
				<li><a href="main.do">首页</a></li>
				<li class="first current_page_item"><a href="documentLibrary.do?actMethod=showDocumentLibraryAction">文档库</a></li>
				<li><a href="jsp/TaskManagement.jsp">日程表</a></li>
				<li><a href="jsp/FriendManagement.jsp">朋友们</a></li>
				<li><a href="#">关于我</a></li>
				<li><a href="#">关于这</a></li>
			</ul>
		</div>
         <div id="userinfo">
           		<a id="userWelcome">Hi,${sessionScope.username}</a>
                <a id="signout" href="user.do?actMethod=quitUserAction">Sign out</a>
                <a id="register" href="jsp/register.jsp">Register</a>
           </div>
	</div>
	<!-- end #header -->
  <div id="centerDocuments">
     <button id="addLibrary" style="margin-left: 800px;">+</button>
     <div id="addLibraryDialog" title="添加新库">
     	库名：<input type="text" id="libraryName" name="libraryName" value="我的新文档库"/>
     	<button id="saveDocLibrary" onclick="onSaveLibraryAction()">保存</button>
     </div>
     <div id="updateLibraryDialog" title="更新库">
     	库名：<input type="text" id="newLibraryName" name="newLibraryName" value=""/>
     	<button id="updateDocLibraryAction" onclick="onUpdateLibraryAction()">更新</button>
     </div>
     <div id="documentLibraryOp" title="操作">
     	<button id="selectDocLibrary" onclick="onOpenLibraryAction()">查看</button>
     	<button id="updateDocLibrary">更新</button>
    	<button id="deleteDocLibrary" onclick="onDeleteLibraryAction()">删除</button>
     </div>
	<table width="200" align="center" border="0">
		<tr>
		<%	
   			Iterator it=libraries.iterator();
   			while(it.hasNext()){
   				Documentlibrary library=(Documentlibrary)it.next();
    			request.setAttribute("library",library);
            			
        %>
      
        <td><button onclick="onLibraryAction(${library.id},'${library.libraryname}')"><img src="images/documents/documentico/0.ico"/></button><br/>${ library.libraryname}</td>
      
      	<%} %>
      	</tr>
      	
    </table>
	</div>
	<!-- end #content -->
	<div style="clear: both;">&nbsp;</div>
			
	<!-- end #page -->
</div>
<div id="footer">
	<p>Copyright (c) 2013 Avery.com. All rights reserved. Design by Avery.</p>
</div>
<!-- end #footer -->
</body>
</html>
